package com.ruoyi.framework.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.dialect.IDialect;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.spring5.dialect.SpringStandardDialect;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.StringTemplateResolver;

//@Configuration
public class TemplateResolverConfig {

    @Bean("templateEngine")
    public SpringTemplateEngine initTemp() {
        // 创建字符串模板引擎对象
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();

        // 内置方言
        IDialect springStandardDialect = new SpringStandardDialect();
        templateEngine.setDialect(springStandardDialect);

        // 字符串解析器
        StringTemplateResolver stringTemplateResolver = new StringTemplateResolver();

        // 使用缓存
        stringTemplateResolver.setCacheable(true);
        stringTemplateResolver.setTemplateMode(TemplateMode.HTML);
        templateEngine.setTemplateResolver(stringTemplateResolver);
        return templateEngine;
    }

}